<?php
 
class Model_DbTable_rate extends Zend_Db_Table_Abstract {
	
	protected $_name = 'user_input';
	

	public function addRating($comm, $stud, $overall, $comments){	
	
		$data = array (
		'community' => $comm,
		'student' => $stud,
		'usefulness' => $overall,
		'comments' => $comments,
		'date_entered' => new Zend_Db_Expr("now()")
		);
		
		$this->insert($data);
	}
		
	
	public function viewComments(){
		

		//$db = Zend_Db_Table_Abstract::getDefaultAdapter();
		$select = new Zend_Db_Select($this->_db);
		$result = $select->from(array('c'=>'user_input'), array('id','comments', 'date_entered'))
					  	->order(array('date_entered DESC'));
	 // Zend_Debug::dump($result->__toString());		
	  return $result;
	}
	
	
/**
	 * Function: avgRatings
	 * This function returns the average ratings of Gradeometer patrons
	 */
	public function avgRatings(){
		//$db = Zend_Db_Table_Abstract::getDefaultAdapter();
		$select = new Zend_Db_Select($this->_db);	
		$result = $select->from(array ('u' =>'user_input'), array(
		'student'=>'avg(student)', 'recount' => 'count(id)',
		'community'=>'avg(community)'));
		//Zend_Debug::dump($result->__toString());
		return $result;	
	}
}